﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.SqlClient;
using System.Linq;

namespace HobSoft.SoccerBet2014.Domain.Implementation.SqlRepository
{
    using Domain.IRepositories;
    using Domain.Models;
    public class GameMappingRepository : ReadWriteSqlEntRepository<GameMapping>, IGameMappingRepository
    {
        public GameMappingRepository(DbContext dbContext)
            : base(dbContext)
        {

        }

        public IList<GameMapping> GetMany(DateTime afterStartTime, DateTime beforeStartTime)
        {
            string query = @"select [MappingID] as [Key]
                                                  ,[BFEventID] as [EventID]
                                                  ,[BookerID] as [BmID]
                                                  ,[MatchID] as [GameID]
                                                  ,[TeamReversal]
                                                  ,[CreateTime] as [LastUpdateTime] 
                                    from MatchMapping where BFEventID in(select EventID from BFEvent where EventTime>@AfterStartTime and EventTime < @BeforeStartTime)";

            var result = DbContext.Database.SqlQuery<GameMapping>(query
                                        , new SqlParameter("@AfterStartTime", afterStartTime)
                                        , new SqlParameter("@BeforeStartTime", beforeStartTime)).ToList();
            return result;
        }
    }
}
